<template>
  <Temp @clear="clear" @close="close">
    <div class="measure">
      <div
        @click="activeTool(item.title)"
        v-for="item in list"
        :key="item.icon"
        :style="{
          color:
            active === item.title
              ? activeColor
              : defaultColor
        }"
      >
        <Icon
          :title="item.title"
          :name="item.icon"
          :font-size="iconSize"
        />
        <span>{{ item.title }}</span>
      </div>
    </div>
  </Temp>
</template>

<script>
import Temp from '../temp'
import Icon from '@/components/icon'
import { getAction } from '@/utils/helper'

const measure = {}
export default {
  components: {
    Temp,
    Icon
  },
  inject: ['viewerId'],
  data() {
    return {
      iconSize: 20,
      activeColor: 'rgba(0, 210, 255, 1)',
      defaultColor: '#D2E6F0',
      active: '',
      list: [
        {
          title: '距离',
          icon: 'juli'
        },
        {
          title: '高度',
          icon: 'gaodu'
        },
        {
          title: '面积',
          icon: 'mianji'
        }
        // {
        //   title: '方位角',
        //   icon: 'jiaodu'
        // }
      ]
    }
  },
  async created() {
    const { toolManager } = await getAction(this.viewerId)
    measure[this.viewerId] = toolManager.measure
  },
  methods: {
    close() {
      this.$emit('close')
    },
    clear() {
      this.active = ''
      measure[this.viewerId].clear()
    },
    activeTool(title) {
      if (this.active === title) {
        this.active = ''
        // measure[this.viewerId].inactive()
        measure[this.viewerId].clear()
        // this.clear()
      } else {
        this.active = title
        switch (title) {
          case '距离':
            // measure[this.viewerId].inactive()
            measure[this.viewerId].clear()
            measure[this.viewerId].length()
            break
          case '高度':
            // measure[this.viewerId].inactive()
            measure[this.viewerId].clear()
            measure[this.viewerId].height()
            break
          case '面积':
            // measure[this.viewerId].inactive()
            measure[this.viewerId].clear()
            measure[this.viewerId].area()
            break
          // case '方位角':
          //   measure[this.viewerId].angle()
          //   break
          default:
            break
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.measure {
  display: grid;
  grid-template-columns: repeat(4, auto);
  column-gap: 10px;

  & > div {
    display: flex;
    align-items: center;

    & > span {
      margin-left: 4px;
      font-size: 14px;
      word-break: keep-all;
      cursor: pointer;
    }
  }
}
</style>
